<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ page import="ihis.model.*"%>
<%@ page import="ihis.core.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@page import="ihis.tms.client.IHISTMSClient"%>

<%
	String loginId = (String) session.getAttribute("loginId");
	if(IHISUtil.isEmpty(loginId)){
		loginId = request.getParameter("loginId");
		System.out.println("session is not available");
	}
	IHISTMSClient tms = new IHISTMSClient();
	String userName = tms.getUserName(loginId);
	
	//  TODO:  아래의 지연 할일 개수를 구하는 별도의 하나의 메소드를 만들 것. 
	TaskFilter filter = new TaskFilter();
	filter.setOwnerId(loginId);
	IHISCore core = new IHISCore();
	ProjectScheduleRiskReport report = (ProjectScheduleRiskReport) core.getReport(IHISConstants.REPORT_RISK, filter);
	List<Task> list = report.getDelayedRiskList();
	int delayedCnt = 0;
	if(list != null){
		delayedCnt += list.size();
	}
	list = report.getPotentialRiskList();
	if(list != null){
		delayedCnt += list.size();
	}
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>IHIS created by Honey Bread(Team 4) in SEP521</title>
	<link rel="stylesheet" href="script/jquery.mobile-1.0a4.1.min.css"/>
    <link rel="stylesheet" href="script/ihis.css"/>
    <script src="script/jquery-1.6.min.js"></script>
    <script src="script/jquery.mobile-1.0a4.1.min.js"></script>
</head>
<body>
	<div id="menuPage" data-role="page" data-theme="a">
		<script type="text/javascript">
		$(function(){
    		$("#scheduleMenu").bind("click", function(){
    			var url = "schedule.jsp?firstLoad=true&periodType=1&ownerType=" + "<%= IHISConstants.OWNERTYPE_PERSON %>"
    					+ "&startDate=" + "<%= new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
    					+ "&loginId=" + "<%=loginId%>";
    			document.location = url;
			});
		});
		
		$(function(){
    		$("#performanceMenu").bind("click", function(){
    			var url = "performance.jsp?firstLoad=true&periodType=1&ownerType=" + "<%= IHISConstants.OWNERTYPE_PERSON %>"
    					+ "&startDate=" + "<%= new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
    					+ "&loginId=" + "<%=loginId%>";
    			document.location = url;
			});
		});
		
		$(function(){
    		$("#predictedCurveMenu").bind("click", function(){
    			var url = "predictedCurve.jsp?firstLoad=true&periodType=1&ownerType=" + "<%= IHISConstants.OWNERTYPE_PROJECT %>"
    					+ "&startDate=" + "<%= new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
    					+ "&loginId=" + "<%=loginId%>";
    			document.location = url;
			});
		});
		
		$(function(){
    		$("#riskMenu").bind("click", function(){
    			var url = "risk.jsp?firstLoad=true&periodType=1&ownerType=" + "<%= IHISConstants.OWNERTYPE_PERSON %>"
    					+ "&startDate=" + "<%= new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
    					+ "&loginId=" + "<%=loginId%>";
    			document.location = url;
			});
		});
		
		$(function(){
    		$("#logoutButton").bind("click", function(){
    			document.location = "index.jsp?loginId=" + "<%=loginId%>"; 
			});
		});
		
		function showWelcome(){
			alert("<%= userName + "(" + loginId + ")" %>님 IHIS 접속을 환영합니다.");
		}
		</script>

		<div data-role="header">
			<a href="#" data-icon="back" data-role="button" id="logoutButton">Logout</a>
			<h1>IHIS Home</h1>
			<a href="javascript:showWelcome()" data-icon="info"  id="idInfo"><%= userName %></a>
		</div>

		<div data-role="content" data-theme="a">
			<h2>통합 TASK 관리 시스템</h2>
			<ul data-role="listview" data-inset="true" data-theme="b">
				<li>
					<a href="#" id="scheduleMenu">
						<h2>Schedule</h2>
						<p>개인/조직 일정 정보</p>
					</a>
				</li>
				<li>
					<a href="#" id="predictedCurveMenu">
						<h2>Predicted Curve</h2>
						<p>일정 추이 정보</p> 
					</a>
				</li>
				<li>
					<a href="#" id="riskMenu">
						<h2>Schedule Risk</h2>
						<p>일정 위험 정보</p>
				<% if(delayedCnt != 0){ %> 
						<span class="ui-li-count"><%= delayedCnt %></span>
				<% } %>
				 	</a>
				 </li>
				<li>
					<a href="#" id="performanceMenu">
						<h2>Schedule Performance</h2>
						<p>개인/조직 일정 성과</p> 
					</a>
				</li>
				<li><a href="info/about.html">About IHIS</a>
				</li>
			</ul>
		</div>
	</div>
</body>
</html>